package com.atguigu.szdz.dcsyl.controller;

import com.atguigu.szdz.dcsyl.common.utils.R;
import com.atguigu.szdz.dcsyl.service.PmjlService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.Operation;
import org.apache.commons.lang.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.*;
import java.util.function.Function;

@RestController
@RequestMapping("/pmjl")
public class PmjlController {
    @Value("${url}")
    String url;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private PmjlService pmjlService;

    /**
     *
     * @return
     */
    @Operation(summary = "获取Echarts图形所需的数据", description = "没有指定请求method，建议使用POST，需要token")
    @RequestMapping("/getPmjlEchartsList")
    public R getPmjlEchartsList() {

        List<Map<String, Object>> pmjlAllList = pmjlService.getPmjlList();
        List<Map<String, Object>> pmjlEchartsList = new ArrayList<>();
        for (Map<String, Object> map : pmjlAllList) {
            Map<String, Object> map1 = new HashMap<>(map);
            double po = Double.parseDouble(String.valueOf(map.get("po")));
            double ph = Double.parseDouble(String.valueOf(map.get("ph")));
            double vo = Double.parseDouble(String.valueOf(map.get("vo")));
            double vn = Double.parseDouble(String.valueOf(map.get("vn")));
            double n = Double.parseDouble(String.valueOf(map.get("n")));


            double density = Double.parseDouble(String.valueOf(map.get("density")));
            double tg = Double.parseDouble(String.valueOf(map.get("tg")));
            double so = Double.parseDouble(String.valueOf(map.get("so")));
            double sh = Double.parseDouble(String.valueOf(map.get("sh")));
            double sh2 = Double.parseDouble(String.valueOf(map.get("sh2")));
            double arf = Double.parseDouble(String.valueOf(map.get("arf")));
            double uti = Double.parseDouble(String.valueOf(map.get("uti")));
            double depth = Double.parseDouble(String.valueOf(map.get("depth")));

            double pob = ((2.184 + 0.062 * (depth - 50) * 0.001 - 0.284 * Math.exp(-1.321 * (depth - 50) * 0.001)) * (depth - 50) + 50 * 1.023) / (depth == 26 ? 1 : depth - 26);
            double dcn = Math.exp(depth * 0.0004158 - 1.28100587);
            double dc = (Math.log(3.282 / (vo * po)) / Math.log(0.0684 * ph / sh)) / (density / 1.03) - 0.649;
            double pp = pob - (pob - 1.023) * Math.pow((dc / dcn), n);
//            double pp = po - (po - ph) * Math.pow((vo / vn), n);
            double pc = (3 * sh - sh2 - 2 * so * tg + (Math.pow(tg, 2) - 1) * arf * pp) / (1 + Math.pow(tg, 2));
            double pf = 3 * sh2 - sh - arf * pp + uti;

            map1.put("pp", pp);
            map1.put("pc", pc);
            map1.put("pf", pf);
            map1.put("depth", depth);

            pmjlEchartsList.add(map1);
        }
        return R.ok().put("pmjlEchartsList", pmjlEchartsList);
    }

    @RequestMapping("/getPmjlList")
    public R getPmjlList(@RequestBody Map<String, Object> params) {
        Integer currentPage = (Integer) params.get("currentPage");
        String keyword = (String) params.get("keyword");

        if ((keyword != "") && (keyword.length() > 0)) {
            keyword
                    = " where (table_code like '%" + keyword + "%') or (well_name like '%"
                    + keyword + "%')";
        }

        List<Map<String, Object>> pmjlList = pmjlService.getPmjlList(currentPage, keyword);
        List<Map<String, Object>> contList = pmjlService.getCount("select count(*) from dc_pmjl" + keyword);
        Object count = contList.get(0).get("count");
        Long c = (Long) count;
        return R.ok().put("pmjlList", pmjlList).put("total", c);
    }

    //同步数据
    @PostMapping("/synData")
    @Transactional(rollbackFor = Exception.class)
    public void synData() {
        System.out.println("从数据服务同步数据!!!");

        // 创建HTTP头部
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);

        // 构建请求体
        Map<String, Object> subFilter = new HashMap<>();
        subFilter.put("symbol", "=");
        subFilter.put("singleValue", "WELLTL100001026");
        subFilter.put("logic", "AND");
        subFilter.put("key", "WELL_ID");

        Map<String, Object> anotherSubFilter = new HashMap<>();
        anotherSubFilter.put("symbol", "IN");
        anotherSubFilter.put("realValue", new String[]{"RT", "DEN", "SP", "GR", "P_AC", "CNL", "RMF", "AT20", "AT10", "SWW"});
        anotherSubFilter.put("logic", "AND");
        anotherSubFilter.put("key", "dataName");

        Map<String, Object> filter = new HashMap<>();
        filter.put("logic", "AND");
        filter.put("subFilter", new Object[]{subFilter, anotherSubFilter});

        Map<String, Object> query = new HashMap<>();
        query.put("filter", filter);

        Map<String, Object> requestBody = new HashMap<>();
        requestBody.put("pageNo", 1);
        requestBody.put("query", query);
        requestBody.put("pageSize", 10);
        requestBody.put("tableName", "X_CD_WELL_SOURCE");

        // 创建HttpEntity
        HttpEntity<Map<String, Object>> entity = new HttpEntity<>(requestBody, headers);

        // 发送POST请求
        ResponseEntity<String> exchange = restTemplate.exchange("http://" + url + "/pmjl/aaa",
                HttpMethod.POST, entity, String.class);
        String bodies = exchange.getBody();

        //解析返回数据
        ObjectMapper mapper = new ObjectMapper();
        String listString = "";
        try {
            JsonNode rootNode = mapper.readTree(bodies);
            JsonNode dataNode = rootNode.path("data");
            String data = dataNode.toString();
            rootNode = mapper.readTree(data);
            dataNode = rootNode.path("list");
            listString = dataNode.toString();
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        //如果无数据，直接结束
        if (listString.length() <= 0 || StringUtils.equals(listString, "")) {
            return;
        }

        //将数据转化为map集合
        JSONArray jsonArray = new JSONArray(String.valueOf(listString));
        List<Map<String, String>> list = new ArrayList<>();
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            Map<String, String> map = new HashMap<>();
            for (Object key : jsonObject.keySet()) {
                String v = String.valueOf(jsonObject.get((String) key));
                map.put((String) key, v);
            }
            list.add(map);
        }

        List<Map<String, String>> mapList = new ArrayList<>();
        for (Map<String, String> map : list) {
            Map<String, String> map1 = new HashMap<>();
            map1.put("well_name", map.get("well_name"));
            map1.put("Po", map.get("Po"));
            map1.put("Ph", map.get("Ph"));
            map1.put("Vo", map.get("Vo"));
            map1.put("Vn", map.get("Vn"));
            map1.put("n", map.get("n"));
            map1.put("SH", map.get("SH"));
            map1.put("Sh", map.get("Sh"));
            map1.put("So", map.get("So"));
            map1.put("tg", map.get("tg"));
            map1.put("arf", map.get("arf"));
            map1.put("UTI", map.get("UTI"));
            map1.put("depth", map.get("depth"));
            mapList.add(map1);
        }

        // 生成表单号
        String uuid = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 12);
        String table_code = "T" + uuid;
        //更新表单数据
//        basicDataService.updateDate(table_code);
        //更新预处理表数据
        pmjlService.updateDate(table_code, mapList);
    }

    @PostMapping("/aaa")
    public String aaa(@RequestBody String aaa) {
        System.out.println("bbbbbbbbbbbbbbbbbbb!!!!!!!!!!!!:" + aaa);
        String json = "{\"code\":0,\"message\":\"操作处理成功\",\"data\":{\"total\":37,\"list\":[{\"well_name\":\"A1\",\"Po\":0.29,\"Ph\":0.29,\"Vo\":0.72,\"Vn\":0.16,\"n\":5,\"SH\":1.35,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.67,\"depth\":1111}" +
                ",{\"well_name\":\"A1\",\"Po\":0.29,\"Ph\":0.29,\"Vo\":0.72,\"Vn\":0.16,\"n\":5,\"SH\":1.36,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.68,\"depth\":1112}" +
                ",{\"well_name\":\"A1\",\"Po\":0.30,\"Ph\":0.30,\"Vo\":0.73,\"Vn\":0.17,\"n\":5,\"SH\":1.37,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.69,\"depth\":1113}" +
                ",{\"well_name\":\"A1\",\"Po\":0.31,\"Ph\":0.31,\"Vo\":0.74,\"Vn\":0.18,\"n\":5,\"SH\":1.38,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.70,\"depth\":1114}" +
                ",{\"well_name\":\"A1\",\"Po\":0.32,\"Ph\":0.32,\"Vo\":0.75,\"Vn\":0.19,\"n\":5,\"SH\":1.39,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.71,\"depth\":1115}" +
                ",{\"well_name\":\"A1\",\"Po\":0.33,\"Ph\":0.33,\"Vo\":0.76,\"Vn\":0.20,\"n\":5,\"SH\":1.40,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.72,\"depth\":1116}" +
                ",{\"well_name\":\"A1\",\"Po\":0.34,\"Ph\":0.34,\"Vo\":0.77,\"Vn\":0.21,\"n\":5,\"SH\":1.41,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.73,\"depth\":1117}" +
                ",{\"well_name\":\"A1\",\"Po\":0.35,\"Ph\":0.35,\"Vo\":0.78,\"Vn\":0.22,\"n\":5,\"SH\":1.42,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.74,\"depth\":1118}" +
                ",{\"well_name\":\"A1\",\"Po\":0.36,\"Ph\":0.36,\"Vo\":0.79,\"Vn\":0.23,\"n\":5,\"SH\":1.43,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.75,\"depth\":1119}" +
                ",{\"well_name\":\"A1\",\"Po\":0.37,\"Ph\":0.37,\"Vo\":0.80,\"Vn\":0.24,\"n\":5,\"SH\":1.44,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.76,\"depth\":1120}" +
                ",{\"well_name\":\"A1\",\"Po\":0.38,\"Ph\":0.38,\"Vo\":0.81,\"Vn\":0.25,\"n\":5,\"SH\":1.45,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.77,\"depth\":1121}" +
                ",{\"well_name\":\"A1\",\"Po\":0.39,\"Ph\":0.39,\"Vo\":0.82,\"Vn\":0.26,\"n\":5,\"SH\":1.46,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.78,\"depth\":1122}" +
                ",{\"well_name\":\"A1\",\"Po\":0.40,\"Ph\":0.40,\"Vo\":0.83,\"Vn\":0.27,\"n\":5,\"SH\":1.47,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.79,\"depth\":1123}" +
                ",{\"well_name\":\"A1\",\"Po\":0.41,\"Ph\":0.41,\"Vo\":0.84,\"Vn\":0.28,\"n\":5,\"SH\":1.48,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.80,\"depth\":1124}" +
                ",{\"well_name\":\"A1\",\"Po\":0.42,\"Ph\":0.42,\"Vo\":0.85,\"Vn\":0.29,\"n\":5,\"SH\":1.49,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.81,\"depth\":1125}" +
                ",{\"well_name\":\"A1\",\"Po\":0.43,\"Ph\":0.43,\"Vo\":0.86,\"Vn\":0.30,\"n\":5,\"SH\":1.50,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.82,\"depth\":1126}" +
                ",{\"well_name\":\"A1\",\"Po\":0.44,\"Ph\":0.44,\"Vo\":0.87,\"Vn\":0.31,\"n\":5,\"SH\":1.51,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.83,\"depth\":1127}" +
                ",{\"well_name\":\"A1\",\"Po\":0.45,\"Ph\":0.45,\"Vo\":0.88,\"Vn\":0.32,\"n\":5,\"SH\":1.52,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.84,\"depth\":1128}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.53,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.85,\"depth\":1129}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.54,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.86,\"depth\":1130}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.55,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.87,\"depth\":1131}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.56,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.88,\"depth\":1132}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.57,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.89,\"depth\":1133}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.58,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.90,\"depth\":1134}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.59,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.91,\"depth\":1135}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.60,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.92,\"depth\":1136}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.61,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.93,\"depth\":1137}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.62,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.94,\"depth\":1138}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.63,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.95,\"depth\":1139}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.64,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.96,\"depth\":1140}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.65,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.97,\"depth\":1141}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.66,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.98,\"depth\":1142}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.67,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":3.99,\"depth\":1143}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.68,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":4.00,\"depth\":1144}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.69,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":4.01,\"depth\":1145}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.70,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":4.02,\"depth\":1146}" +
                ",{\"well_name\":\"A1\",\"Po\":0.46,\"Ph\":0.46,\"Vo\":0.89,\"Vn\":0.33,\"n\":5,\"SH\":1.71,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":4.03,\"depth\":1147}" +
                ",{\"well_name\":\"A1\",\"Po\":0.47,\"Ph\":0.47,\"Vo\":0.90,\"Vn\":0.34,\"n\":5,\"SH\":1.72,\"Sh\":0.92,\"So\":0.67,\"tg\":0.34,\"bt\":0.67,\"arf\":0.67,\"Pp\":0.67,\"UTI\":4.04,\"depth\":1148}]}}";
        return json;
    }

    @PostMapping("/postProcessData")
    @Transactional(rollbackFor = Exception.class)
    public R postProcessData() {
        List<Map<String, Object>> pmjlList = pmjlService.getPmjlList();
        Function<Object, String> func = value -> {
            return processData(value, "0", num -> num < 0 ? "0" : num.toString());
        };
        if (pmjlList != null && pmjlList.size() > 0) {
            String table_code = pmjlList.get(0).get("table_code").toString();
            List<Map<String, String>> mapList = new ArrayList<>();
            for (int i = 0; i < pmjlList.size(); i++) {
                Map<String, Object> map = pmjlList.get(i);
                Map<String, String> map1 = new HashMap<>();
                map1.put("well_name", map.get("well_name").toString());
                map1.put("Po", map.get("Po").toString());
                map1.put("Ph", map.get("Ph").toString());
                map1.put("Vo", map.get("Vo").toString());
                map1.put("Vn", func.apply(map.get("Vn")));
                map1.put("n", map.get("n").toString());
                map1.put("SH", map.get("SH").toString());
                map1.put("Sh", map.get("Sh").toString());
                map1.put("So", map.get("So").toString());
                map1.put("tg", map.get("tg").toString());
                map1.put("arf", map.get("arf").toString());
                map1.put("UTI", map.get("UTI").toString());
                map1.put("depth", map.get("depth").toString());
                mapList.add(map1);
            }

            pmjlService.updateDate(table_code, mapList);
        }
        return R.ok("success");
    }

    /**
     * 数据预处理
     *
     * @param src
     * @param defaults
     * @param func
     * @return
     */
    private String processData(Object src, String defaults, Function<Float, String> func) {
        if (src == null) return defaults;
        Float data = Float.valueOf(src.toString());
        return func == null ? defaults : func.apply(data);
    }

    @PostMapping("/normalizationData")
    @Transactional(rollbackFor = Exception.class)
    public R normalizationData() {
        List<Map<String, Object>> pmjlList = pmjlService.getPmjlList();
        if (pmjlList != null && pmjlList.size() > 0) {
            String table_code = pmjlList.get(0).get("table_code").toString();
            List<Map<String, String>> mapList = new ArrayList<>();
            for (int i = 0; i < pmjlList.size(); i++) {
                Map<String, Object> map = pmjlList.get(i);
                Map<String, String> map1 = new HashMap<>();
                map1.put("well_name", map.get("well_name").toString());
                map1.put("Po", map.get("Po").toString());
                map1.put("Ph", map.get("Ph").toString());
                map1.put("Vo", map.get("Vo").toString());
                map1.put("Vn", map.get("Vn").toString());
                map1.put("n", map.get("n").toString());
                map1.put("SH", map.get("SH").toString());
                map1.put("Sh", map.get("Sh").toString());
                map1.put("So", map.get("So").toString());
                map1.put("tg", map.get("tg").toString());
                map1.put("arf", map.get("arf").toString());
                map1.put("UTI", map.get("UTI").toString());
                map1.put("depth", map.get("depth").toString());
                mapList.add(map1);
            }

            pmjlService.updateDate(table_code, mapList);
        }

        return R.ok("success");
    }

}
